package com.party.core.service.photo.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.photo.PhotosImgInfoReadDao;
import com.party.core.dao.write.photo.PhotosImgInfoWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.photo.PhotosImgInfo;
import com.party.core.model.photo.PhotosImgInfoWithResource;
import com.party.core.service.photo.IPhotosImgInfoService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/5/30 14:28
 */
@Service
public class PhotosImgInfoService implements IPhotosImgInfoService {

    @Autowired
    private PhotosImgInfoReadDao photosImgInfoReadDao;

    @Autowired
    private PhotosImgInfoWriteDao photosImgInfoWriteDao;

    @Override
    public String insert(PhotosImgInfo photosImgInfo) {
        BaseModel.preInsert(photosImgInfo);
        boolean result = photosImgInfoWriteDao.insert(photosImgInfo);
        if (result) {
            return photosImgInfo.getId();
        }
        return null;
    }

    @Override
    public boolean update(PhotosImgInfo photosImgInfo) {
        return photosImgInfoWriteDao.update(photosImgInfo);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return photosImgInfoWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return photosImgInfoWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return photosImgInfoWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return photosImgInfoWriteDao.batchDelete(ids);
    }

    @Override
    public PhotosImgInfo get(String id) {
        return photosImgInfoReadDao.get(id);
    }

    @Override
    public List<PhotosImgInfo> listPage(PhotosImgInfo photosImgInfo, Page page) {
        return photosImgInfoReadDao.listPage(photosImgInfo, page);
    }

    @Override
    public List<PhotosImgInfo> list(PhotosImgInfo photosImgInfo) {
        return listPage(photosImgInfo, null);
    }

    @Override
    public List<PhotosImgInfo> batchList(Set<String> ids, PhotosImgInfo photosImgInfo, Page page) {
        return photosImgInfoReadDao.batchList(ids, null, page);
    }

    @Override
    public List<PhotosImgInfoWithResource> listPageByTag(String tagId, PhotosImgInfo photosImgInfo, Map<String, Object> params, Page page) {
        return photosImgInfoReadDao.listPageByTag(tagId, photosImgInfo, params, page);
    }

    @Override
    public List<Map<String, String>> listTimeLine(String photosId, Page page) {
        return photosImgInfoReadDao.listTimeLine(photosId, page);
    }

    @Override
    public Integer getCount(String photosId, String tagId) {
        return photosImgInfoReadDao.getCount(photosId, tagId);
    }

    @Override
    public List<PhotosImgInfoWithResource> listTimeLineData(String takeTime, String photosId, Map<String, Object> params, Page page) {
        return photosImgInfoReadDao.listTimeLineData(takeTime, photosId, params, page);
    }

    @Override
    public List<PhotosImgInfo> findByPhotoId(String photoId) {
        PhotosImgInfo photosImgInfo = new PhotosImgInfo();
        photosImgInfo.setPhotosId(photoId);
        return photosImgInfoReadDao.listPage(photosImgInfo, null);
    }

    @Override
    public void deleteByPhotoId(String photoId) {
        photosImgInfoWriteDao.deleteByPhotoId(photoId);
    }

    @Override
    public PhotosImgInfo getImgInfo(String id) {
        return photosImgInfoReadDao.getImgInfo(id);
    }

    @Override
    public List<PhotosImgInfo> queryThirdImgList(String memberId, List<String> ids) {
        return photosImgInfoReadDao.queryThirdImgList(memberId, ids);
    }
}
